
import numpy as np

def do_fv(data,vs,x=None, sx=0,dt=1e-2, dx=50, NORM=False, PRINT=False, fs=-1, fe=1e10):
    I = np.sqrt(np.array(-1, dtype='complex'))
    PI=np.pi

    nx,nt = data.shape
    if x is None:
        x = np.arange(nx)*dx
    t = np.arange(nt)*dt

    XF = np.zeros([nx,nt],dtype='complex')
    for ix in range(nx):
        XF[ix,:] = np.fft.fft(data[ix,:])
        if PRINT:
            print('\r FX:{}|{}'.format(ix,nx),end='', flush=True)
    FX = XF.T
    f = np.arange(nt)*1/t.max()
    if PRINT:
        print('')
    nv=len(vs)
    FV = np.zeros([nt,nv],dtype='complex')
    idx_valid = []
    for j in range(nt//2):
        if f[j]<fs or f[j]>fe:
            continue
        idx_valid.append(j)
        for i,v in enumerate(vs):
            # FV[j,i] = np.sum(np.exp(I*2*PI*np.abs(x-sx)/v*f[j])*FX[j,:])
            FV[j,i] = np.sum(np.exp(I*2*PI*(x-sx)/v*f[j])*FX[j,:])
        if NORM:
            FV[j,:] = FV[j,:]/np.abs(FV[j,:]).max()
        if PRINT:
            print('\r FV:{}|{}'.format(j,nt),end='')

    return FV[idx_valid,:], f[idx_valid],vs
